package com.pengcheng.hnweb.controller;

import com.pengcheng.hnweb.service.DbService;
import com.pengcheng.hnweb.util.Common;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

@Controller
@Slf4j
public class MobileController {
    @Autowired
    private Common common;
    @Autowired
    private DbService dbService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @RequestMapping("/m/{action}")
    public String action(HttpServletRequest request, Model model, @PathVariable("action") String action)
    {
        Map<String,String> params=new HashMap<>();
        Map<String,String[]> map=request.getParameterMap();
        for(String key:map.keySet())
        {
            params.put(key,common.join(map.get(key)));
        }
        model.addAttribute("json_param",common.tojson(params));
        return "m/"+action;
    }
}
